import axios from "axios";
const url = "https://api.xinyew.cn/api/yanxuantc";
// 上传文件的函数
export const requestMethod = async ({
  file,
  data,
  headers,
  withCredentials,
  action = url,
}: any) => {
  const formData = new FormData();
  const filename = file?.file ? file.file : file;
  formData.append("file", filename as any);
  try {
    const response: any = await axios.post(action, formData, {
      headers: {
        "Content-Type": "multipart/form-data"
      },
    });
    if (response.errno == 1) {
      return {
        status: "failed",
        error: response.error
      };
    }
    return {
      status: "success",
      data: { ...response.data.data }
    };
  } catch (error: any) {
    return {
      status: "failed",
      error: error.error
    };
  }
};
